package tarea;

import tarea.*;
import clases.cds;
import pilas.pila;

/**
 *
 * @author D4y4
 */
public class Apilar extends javax.swing.JFrame {

    /**
     * Creates new form Apilar
     */
    public Apilar() {
        initComponents();
    }

    pila nuevaPila;
    pila cd;

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        btnAsignarMemoria = new javax.swing.JButton();
        txtTamañoPila = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        btnDesapilarDato = new javax.swing.JButton();
        btnMostrarPila = new javax.swing.JButton();
        btnDatoSUperior = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        btnApilarDato = new javax.swing.JButton();
        txtDatos1 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtareaReporte = new javax.swing.JTextArea();
        jPanel3 = new javax.swing.JPanel();
        btnDesapilarDato1 = new javax.swing.JButton();
        btnMostrarPila1 = new javax.swing.JButton();
        btnDatoSUperior1 = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        btnApilarrCds = new javax.swing.JButton();
        txtTitulo = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        cbxCategoria = new javax.swing.JComboBox();
        txtAutor = new javax.swing.JTextField();
        txtAñoPublicacion = new javax.swing.JTextField();
        btnDesapilarCds = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        txtCadena = new javax.swing.JTextField();
        btnVerificar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setText("tamaño de la pila");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 30, -1, -1));

        btnAsignarMemoria.setText("Asignar memoria");
        btnAsignarMemoria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAsignarMemoriaActionPerformed(evt);
            }
        });
        getContentPane().add(btnAsignarMemoria, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 30, -1, -1));
        getContentPane().add(txtTamañoPila, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 20, 90, 40));

        jPanel1.setBorder(new javax.swing.border.MatteBorder(null));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        btnDesapilarDato.setText("Desapilar Dato");
        btnDesapilarDato.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDesapilarDatoActionPerformed(evt);
            }
        });
        jPanel1.add(btnDesapilarDato, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 20, -1, -1));

        btnMostrarPila.setText("MostrarPila");
        btnMostrarPila.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMostrarPilaActionPerformed(evt);
            }
        });
        jPanel1.add(btnMostrarPila, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 20, -1, -1));

        btnDatoSUperior.setText("Obtener dato superior");
        btnDatoSUperior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDatoSUperiorActionPerformed(evt);
            }
        });
        jPanel1.add(btnDatoSUperior, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 60, -1, -1));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 160, 320, 100));

        jPanel2.setBorder(new javax.swing.border.MatteBorder(null));
        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        btnApilarDato.setText("Apilar datos");
        btnApilarDato.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnApilarDatoActionPerformed(evt);
            }
        });
        jPanel2.add(btnApilarDato, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 20, -1, -1));
        jPanel2.add(txtDatos1, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 20, 60, 30));

        jLabel3.setText("Ingresar los datos");
        jPanel2.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 20, -1, -1));

        getContentPane().add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 70, 320, 80));

        txtareaReporte.setColumns(20);
        txtareaReporte.setRows(5);
        jScrollPane1.setViewportView(txtareaReporte);

        getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 70, 180, 120));

        jPanel3.setBorder(new javax.swing.border.MatteBorder(null));
        jPanel3.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        btnDesapilarDato1.setText("Desapilar Dato");
        btnDesapilarDato1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDesapilarDato1ActionPerformed(evt);
            }
        });
        jPanel3.add(btnDesapilarDato1, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 20, -1, -1));

        btnMostrarPila1.setText("MostrarPila");
        btnMostrarPila1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMostrarPila1ActionPerformed(evt);
            }
        });
        jPanel3.add(btnMostrarPila1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 20, -1, -1));

        btnDatoSUperior1.setText("Obtener dato superior");
        btnDatoSUperior1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDatoSUperior1ActionPerformed(evt);
            }
        });
        jPanel3.add(btnDatoSUperior1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 60, -1, -1));

        getContentPane().add(jPanel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 160, 320, 100));

        jPanel4.setBorder(new javax.swing.border.MatteBorder(null));
        jPanel4.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel2.setText("categoria");
        jPanel4.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 90, -1, -1));

        jLabel4.setText("titulo");
        jPanel4.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(21, 12, -1, -1));

        jLabel5.setText("autor");
        jPanel4.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 50, -1, -1));

        btnApilarrCds.setText("apilar cds");
        btnApilarrCds.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnApilarrCdsActionPerformed(evt);
            }
        });
        jPanel4.add(btnApilarrCds, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 120, -1, -1));
        jPanel4.add(txtTitulo, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 10, 60, -1));

        jLabel6.setText("año publicacion");
        jPanel4.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 130, -1, -1));

        cbxCategoria.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "musica", "ciencia", "ficcon" }));
        jPanel4.add(cbxCategoria, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 90, 80, -1));
        jPanel4.add(txtAutor, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 50, 60, -1));
        jPanel4.add(txtAñoPublicacion, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 130, 80, -1));

        btnDesapilarCds.setText("desapilar cds");
        btnDesapilarCds.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDesapilarCdsActionPerformed(evt);
            }
        });
        jPanel4.add(btnDesapilarCds, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 160, -1, -1));

        getContentPane().add(jPanel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 330, 550, 220));

        jLabel7.setText("Ingrese Cadena:");
        getContentPane().add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 270, -1, -1));

        txtCadena.setText("dayana&anayad");
        getContentPane().add(txtCadena, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 270, 200, 30));

        btnVerificar.setText("Verificar Cadena");
        btnVerificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVerificarActionPerformed(evt);
            }
        });
        getContentPane().add(btnVerificar, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 270, -1, -1));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAsignarMemoriaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAsignarMemoriaActionPerformed
        int tamaño = Integer.parseInt(txtTamañoPila.getText());
        nuevaPila = new pila(tamaño);
    }//GEN-LAST:event_btnAsignarMemoriaActionPerformed

    private void btnApilarDatoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnApilarDatoActionPerformed
        int dato = Integer.parseInt(txtDatos1.getText());
     nuevaPila.apilar(dato);
    }//GEN-LAST:event_btnApilarDatoActionPerformed

    private void btnDesapilarDato1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDesapilarDato1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnDesapilarDato1ActionPerformed

    private void btnMostrarPila1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMostrarPila1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnMostrarPila1ActionPerformed

    private void btnDatoSUperior1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDatoSUperior1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnDatoSUperior1ActionPerformed

    private void btnDatoSUperiorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDatoSUperiorActionPerformed
        Object salida=nuevaPila.obtenerDatoSuperior();
        txtareaReporte.setText(salida.toString());
    }//GEN-LAST:event_btnDatoSUperiorActionPerformed

    private void btnMostrarPilaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMostrarPilaActionPerformed
        String salida=nuevaPila.mostrarPila();
        txtareaReporte.setText(salida);
    }//GEN-LAST:event_btnMostrarPilaActionPerformed

    private void btnDesapilarDatoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDesapilarDatoActionPerformed
        Object datoPila = nuevaPila.desapilar();
        txtareaReporte.setText(datoPila.toString());
    }//GEN-LAST:event_btnDesapilarDatoActionPerformed

    private void btnApilarrCdsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnApilarrCdsActionPerformed
        String nombre=txtAutor.getText();
        String titulo=txtTitulo.getText();
        String tipoMusica=cbxCategoria.getSelectedItem().toString();
        int publicacion= Integer.parseInt(txtAñoPublicacion.getText());
        
        cds nuevoCds=new cds(titulo, nombre, publicacion, tipoMusica);
        cd.apilar(nuevoCds);
    }//GEN-LAST:event_btnApilarrCdsActionPerformed

    private void btnDesapilarCdsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDesapilarCdsActionPerformed
        cds dato=(cds)cd.desapilar();
        String titulo=dato.titulo;
        String autor=dato.autor;
        String categoria=dato.categoria;
        int año=dato.añoPublicacion;
        String mensaje=" "+titulo+" "+autor+" "+categoria+" "+año;
        txtareaReporte.setText(mensaje);
    }//GEN-LAST:event_btnDesapilarCdsActionPerformed

    private void btnVerificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVerificarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnVerificarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Apilar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Apilar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Apilar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Apilar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Apilar().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnApilarDato;
    private javax.swing.JButton btnApilarrCds;
    private javax.swing.JButton btnAsignarMemoria;
    private javax.swing.JButton btnDatoSUperior;
    private javax.swing.JButton btnDatoSUperior1;
    private javax.swing.JButton btnDesapilarCds;
    private javax.swing.JButton btnDesapilarDato;
    private javax.swing.JButton btnDesapilarDato1;
    private javax.swing.JButton btnMostrarPila;
    private javax.swing.JButton btnMostrarPila1;
    private javax.swing.JButton btnVerificar;
    private javax.swing.JComboBox cbxCategoria;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField txtAutor;
    private javax.swing.JTextField txtAñoPublicacion;
    private javax.swing.JTextField txtCadena;
    private javax.swing.JTextField txtDatos1;
    private javax.swing.JTextField txtTamañoPila;
    private javax.swing.JTextField txtTitulo;
    private javax.swing.JTextArea txtareaReporte;
    // End of variables declaration//GEN-END:variables
}
